package com.demo.test;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import cc.ecore.spring.jfinal.plugin.IocKit;
import cc.ecore.spring.jfinal.plugin.SpringPlugin;

import com.demo.controller.BlogController;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.render.ViewType;

public class CommonConfig extends JFinalConfig {

	@Autowired
	private ApplicationContext ctx;

	@Override
	public void configConstant(Constants me) {
		ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(JFinal.me().getServletContext());
		IocKit.processInjection(ctx, this);

		System.out.println("configConstant 缓存 properties");
		loadPropertyFile("common.properties");

		System.out.println("configConstant 设置字符集");
		me.setEncoding("UTF-8");

		System.out.println("configConstant 设置是否开发模式");
		me.setDevMode(getPropertyToBoolean("devMode", true));
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configRoute(Routes me) {
		System.out.println("configRoute");
		me.add("/blog", BlogController.class);
		me.add("/", BlogController.class);
	}

	@Override
	public void configPlugin(Plugins me) {
		Boolean devMode = getPropertyToBoolean("devMode", true);// 开发模式
		System.out.println("configPlugin 配置SpringPlugin插件");
		me.add(new SpringPlugin(ctx));
	}

	@Override
	public void configInterceptor(Interceptors me) {
		System.out.println("configInterceptor");
	}

	@Override
	public void configHandler(Handlers me) {
		System.out.println("configHandler");
	}

}
